package com.zhny.project.txt.clean.controller;

import com.zhny.common.utils.poi.ExcelUtil;
import com.zhny.framework.aspectj.lang.annotation.Log;
import com.zhny.framework.aspectj.lang.enums.BusinessType;
import com.zhny.framework.web.controller.BaseController;
import com.zhny.framework.web.domain.AjaxResult;
import com.zhny.framework.web.page.TableDataInfo;
import com.zhny.project.txt.clean.service.ICleanService;
import com.zhny.project.txt.dataset.domain.TxtDataset;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据清洗Controller
 *
 * @author yanqun
 * @date 2019-12-10
 */
@Controller
@RequestMapping("/txt/clean")
public class CleanController extends BaseController
{
    private String prefix = "txt/clean";

    @Autowired
    private ICleanService cleanService;

    @RequiresPermissions("txt:clean:view")
    @GetMapping()
    public String clean()
    {
        return prefix + "/clean";
    }

    /**
     * 查询数据清洗列表
     */
    @RequiresPermissions("txt:clean:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TxtDataset txtDataset)
    {
        startPage();
        List<TxtDataset> list = cleanService.selectCleanList(txtDataset);
        return getDataTable(list);
    }

    /**
     * 导出数据清洗列表
     */
    @RequiresPermissions("txt:clean:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TxtDataset txtDataset)
    {
        List<TxtDataset> list = cleanService.selectCleanList(txtDataset);
        ExcelUtil<TxtDataset> util = new ExcelUtil<TxtDataset>(TxtDataset.class);
        return util.exportExcel(list, "clean");
    }

    /**
     * 新增数据清洗
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据清洗
     */
    @RequiresPermissions("txt:clean:add")
    @Log(title = "数据清洗", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TxtDataset txtDataset)
    {
        return toAjax(cleanService.insertClean(txtDataset));
    }

    /**
     * 修改数据清洗
     */
    @GetMapping("/edit/{datasetKey}")
    public String edit(@PathVariable("datasetKey") String datasetKey, ModelMap mmap)
    {
        TxtDataset txtDataset = cleanService.selectCleanById(datasetKey);
        mmap.put("clean", txtDataset);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据清洗
     */
    @RequiresPermissions("txt:clean:edit")
    @Log(title = "数据清洗", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TxtDataset txtDataset)
    {
        return toAjax(cleanService.updateClean(txtDataset));
    }

    /**
     * 删除数据清洗
     */
    @RequiresPermissions("txt:clean:remove")
    @Log(title = "数据清洗", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cleanService.deleteCleanByIds(ids));
    }


}
